#!/usr/bin/env ruby # Define a class for our repeated and convenient use class DNAseq < String # Declare a property (or "attribute" that is get-able and set-able from outside the object) # attr_accessor :seq # <-- not needed anymore, we're a String # Constructor...called automatically when new() is called def initialize(seq) # Call our parent class' initialize using seq (parent is String) super(seq) end # Method to calculate Tm, melting temperature (short oligos, very rough est. and assumptions) def meltingTemp(celcius=true) gc = gcCount() at = count("atAT") # <-- calls String#count automatically tm = 4 * gc + 2 * at unless(celcius) tm = (9/5) * tm + 32 end return tm end # Method to tell us number of GCs def gcCount() count("gcGC") end end # Example usage: # create some DNAseq objects dna1 = DNAseq.new("aattggcc") dna2 = DNAseq.new("atgggcCCgcAga") # Use dna1 and ask it questions puts "DNA1 uppercased is '#{dna1.upcase}' with #{dna1.gcCount()} GCs and a est Tm of #{dna1.meltingTemp()}C" # Retrieve info from dna2 for use later gcCount2 = dna2.gcCount() tm2 = dna2.meltingTemp(false) # later use puts "DNA2 revComp is '#{dna2.reverse.tr('actgACTG', 'tgacTGAC')}' with #{gcCount2} GCs and a est Tm of #{tm2}F"